package main

import (
	"flag"
	"k8s.io/api/core/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
	"runtime"
)

func main() {
	var kubeconfig *string
	switch runtime.GOOS {
	case "darwin":
		kubeconfig = flag.String("config", "./config", "absolute path to the kubeconfig file")
	case "windows":
		kubeconfig = flag.String("config", "D:\\Go\\gopath\\src\\go_learn\\docker\\k8s\\config", "absolute path to the kubeconfig file")
	case "linux":
		kubeconfig = flag.String("config", "/root/.kube/config", "absolute path to the kubeconfig file")
	}
	flag.Parse()
	config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
	if err != nil {
		println("build config from Flag err :%s", err)
	}

	clientset, err := kubernetes.NewForConfig(config)
	if err != nil {
		println("get clientset error %s", err)
		return
	}

	podClient := clientset.CoreV1().Pods(v1.NamespaceDefault)
	var line = int64(100)
	options := &v1.PodLogOptions{TailLines: &line}
	podLogClient := podClient.GetLogs("nginx-ingress-controller-85b7f69647-x7rdq", options)

	println(podLogClient.Name)

}
